package com.ruoyi.common.utils.bean;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class DateRanger {

    /**
     * 请求参数
     */
    @JsonIgnore
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Map<String, String> params = new HashMap<>();

    public LocalDateTime getBeginTime() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
        return params.get("beginTime") == null ? null : LocalDateTime.parse(params.get("beginTime").substring(0, 10) + "T00:00:00", formatter);
    }

    public LocalDateTime getEndTime() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
        return params.get("endTime") == null ? null : LocalDateTime.parse(params.get("endTime").substring(0, 10) + "T23:59:59", formatter);
    }

    public static boolean isAllNotEmpty(DateRanger dateRanger) {
        return dateRanger != null && dateRanger.getParams() != null && dateRanger.getBeginTime() != null && dateRanger.getEndTime() != null;
    }

}
